// import store from '../stores'
import pinia from '@/stores/'
import { useMenuStore } from '@/stores/menu'
const useMenu = useMenuStore(pinia)
// 全局指令 v-color
// app.directive('color',{
//     mounted(el,binding){
//         el.style.color = binding.value
//     },
//     updated(el,binding){
//         el.style.color = binding.value
//     }
// })
/**
 * 颜色指令 v-color
 */
export const color = (el, binding) => {
    //mounted | updated
    el.style.color = binding.value
}

/**
 * 按钮权限指令 v-permission
 *  <button v-permission="[DELETE-GOODS]">删除</button>
 */
export const permission = (el, binding) => {
    // const resources = store.getters['menu/resources']
    const resources = useMenu.resourceList

    const value = binding.value

    const isOk = resources.some(item=>item===value)
    if(!isOk){
        // let type = document.createAttribute('type')
        // type.nodeValue = 'info'
        // let disabled = document.createAttribute('disabled')
        // el.attributes.setNamedItem(type)
        // el.attributes.setNamedItem(disabled)
        
        // el.setAttribute('type','info')
        // el.setAttribute('aria-disabled',true) 
        // el.setAttribute('aria-disabled','true') 
        // console.log(1)
        

        // el.setAttribute('disabled',true) 
        // el.getAttribute('disabled')
        // console.log(el.getAttribute('disabled'))


        // console.log(el.getAttribute('aria-disabled'))
        // el.setAttribute('aria-disabled',false) 
        // console.log(el.getAttribute('aria-disabled'))

        // console.log(el.getAttribute('disabled'))
        // el.setAttribute('disabled',false) 
        // console.log(el.getAttribute('disabled'))
        
        // el.removeAttribute('disabled')

        el.classList.add("is-disabled")

        // 不显示按钮
        // el.remove() 
    }
    // binding.value => DELETE-GOODS
    // el => button

    // 获取权限按钮值，DELETE-GOODS 与 登录用户角色对应的按钮资源进行比较，
    // 如果有匹配值显示权限按钮， 如果没有值，隐藏权限按钮
}
